//
//  LXHotTableViewController.m
//  喜马拉雅改良版框架
//
//  Created by liuxin on 15/12/28.
//  Copyright © 2015年 蓝鸥科技. All rights reserved.
//

#import "LXHotTableViewController.h"

@interface LXHotTableViewController ()
@property(nonatomic,strong)NSMutableArray *allArray;
@end

@implementation LXHotTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    self.allArray  = [NSMutableArray array];
    self.navigationItem.title = self.NavigationTitle;
    UIImage *backImage = [UIImage imageNamed:@"icon_back_h@2x.png"];
    backImage = [backImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithImage:backImage style:UIBarButtonItemStyleDone target:self action:@selector(backAction)];
    [self getData];
    [self createTableView];
}
-(void)backAction{
    [self.navigationController popViewControllerAnimated:YES];
}
-(void)getData{
    NSString *urlStr = [NSString stringWithFormat:@"http://mobile.ximalaya.com/mobile/discovery/v1/rankingList/%@?device=iphone&key=%@&pageId=1&pageSize=40", self.contentType, self.key];
    [AFNetworkTool getUrl:urlStr body:nil result:HXJSON headerFile:nil success:^(id result) {
        NSArray *array = result[@"list"];
        for (NSDictionary *dic in array) {
            LXHotModel *temp = [LXHotModel new];
            [temp setValuesForKeysWithDictionary:dic];
            [self.allArray addObject:temp];
        }
        [self.tableView reloadData];
    } failure:^(NSError *error) {
    }];
}
-(void)createTableView{
    [self.tableView registerClass:[LXHotTableViewCell class] forCellReuseIdentifier:@"cell"];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _allArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    LXHotTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    cell.index = indexPath.row;
    cell.cellModel = [_allArray objectAtIndex:indexPath.row];
    return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 80;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    KBAlbumsDetailViewController *detail = [KBAlbumsDetailViewController new];
    LXHotModel *album =  [_allArray objectAtIndex:indexPath.row];
    detail.albumId = [NSString stringWithFormat:@"%ld",album.albumId];
    [self.navigationController pushViewController:detail animated:YES];
}

@end
